<template>
    <div style="float:left">
        <NumberInput :formatter="value => formatter.dataFormatter(value,inputConfig.scale?inputConfig.scale:2)"
                     :placeholder="inputConfig.placeholder"
                     :precision="(inputConfig.scale||inputConfig.scale==0)?inputConfig.scale:2" :step="0"
                     :style="{width:'100px'}"
                     v-model="values[valueIndex]"></NumberInput>
    </div>
</template>
<style lang="less" scoped>
</style>
<script>
    import ruiMixin from "../../../mixin/rule-mixin";
    import NumberInput from '_c/rui-auto/rewrite/number-input'
    import {currencyFormat, numberFormat} from "@/libs/tools";

    export default {
        name: 'number-type',
        mixins: [ruiMixin],
        components: {
            'NumberInput': NumberInput
        },
        props: {
            values: {
                type: Array,
                require: true
            },
            valueIndex: {
                type: Number,
                require: true
            },

            formatter: {
                type: Object,
                default: () => {
                    return {
                        dataFormatter: numberFormat,
                        currencyFormat: currencyFormat
                    };
                }
            }
        },
        data() {
            return {
                inputConfig: {"placeholder": "", "scale": 6, "type": "number", "min": -999999, "max": 99999}
                ,
            }
        },
        computed: {},
        methods: {
            valueChecks(value) {
                if (this.inputConfig.min && value < this.inputConfig.min) {
                    this.$emit('checkError', true, '值不能小于' + this.inputConfig.min);
                    return
                }
                if (this.inputConfig.max && value > this.inputConfig.max) {
                    this.$emit('checkError', true, '值不能大于' + this.inputConfig.max);
                    return
                }
                this.$emit('checkError', false, '');
            }
        },
        watch: {
            values() {
                this.valueChecks(this.values[this.valueIndex])
            }
        }
    }
</script>
